package geradatawarehouse.runnable;

import geradatawarehouse.bean.abs.AbstractAluno;
import geradatawarehouse.dao.oracle.abs.AbstractAlunoOracleDAO;
import geradatawarehouse.runnable.abs.AbstractAlunoRecorder;

import org.apache.log4j.Logger;

public abstract class AbstractAlunoLoader<T extends AbstractAluno> implements
		Runnable {

	protected final AbstractAlunoOracleDAO<T> dao;
	protected final AbstractAlunoRecorder<T> recorder;

	private static final Logger LOGGER = Logger
			.getLogger(AbstractAlunoLoader.class);

	public AbstractAlunoLoader(final AbstractAlunoOracleDAO<T> dao,
			final AbstractAlunoRecorder<T> recorder) {
		this.dao = dao;
		this.recorder = recorder;
	}

	@Override
	public void run() {
		try {
			this.dao.executeSelectAll();
			T a = null;
			while ((a = this.dao.next()) != null) {
				this.recorder.queue(a);
			}
			// Envia o sinal de parada para o recorder
			this.recorder.stop();
		} catch (Exception e) {
			AbstractAlunoLoader.LOGGER.error("Thread " + this
					+ " finalizada por causa de Exceção: " + e);
		}
	}

}